namespace Roids.SL.Framework
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;

    public static class Randomizer
    {
        public static Random Random = new Random(DateTime.Now.Millisecond);

        public static Vector2 GetVector()
        {
            return new Vector2 {X = Random.Next(-50, 50), Y = Random.Next(-50, 50)};
        }

        public static int Next(int maxValue)
        {
            return Random.Next(maxValue);
        }

        public static double Next(double maxValue)
        {
            return Random.NextDouble()*maxValue;
        }

        public static Vector2 Create(float x, float y)
        {
            return new Vector2
                       {
                           X = (float) Next(x) - x/2,
                           Y = (float) Next(y) - y/2
                       };
        }

        public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> list)
        {
            if (list == null) return new List<T>();

            var withKeys = from item in list
                           select new {item, key = Next(list.Count() + 1)};

            return from pair in withKeys
                   orderby pair.key
                   select pair.item;
        }
    }
}